﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DigitalRubyShared;

public class FGRotate : MonoBehaviour
{
    public GameObject targetObject;       
    private RotateGestureRecognizer rotateGesture;

    private ScaleGestureRecognizer scaleGesture;
    // Start is called before the first frame update
    void Start()
    {
        CreateRotateGesture();
        CreateScaleGesture();
        scaleGesture.AllowSimultaneousExecution(rotateGesture);
    }

    private void CreateRotateGesture()
    {
        rotateGesture = new RotateGestureRecognizer();
        rotateGesture.StateUpdated += RotateGestureCallback;
        rotateGesture.AllowSimultaneousExecutionWithAllGestures();
        FingersScript.Instance.AddGesture(rotateGesture);
    }

    private void RotateGestureCallback(DigitalRubyShared.GestureRecognizer gesture)
    {
        Debug.Log(gesture.State.ToString());
        if (gesture.State == GestureRecognizerState.Executing)
        {
            targetObject.transform.Rotate(0.0f, 0.0f, rotateGesture.RotationRadiansDelta * Mathf.Rad2Deg);
        }
    }


    private void ScaleGestureCallback(DigitalRubyShared.GestureRecognizer gesture)
    {
        if (gesture.State == GestureRecognizerState.Executing)
        {
            targetObject.transform.localScale *= scaleGesture.ScaleMultiplier;
        }
    }

    private void CreateScaleGesture()
    {
        scaleGesture = new ScaleGestureRecognizer();
        scaleGesture.StateUpdated += ScaleGestureCallback;
        FingersScript.Instance.AddGesture(scaleGesture);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
